//
//  SeeMoreAlarmBtnCell.m
//  efairy
//
//  Created by 李锋 on 2019/3/1.
//  Copyright © 2019年 East. All rights reserved.
//

#import "SeeMoreAlarmBtnCell.h"

@implementation SeeMoreAlarmBtnCell

- (void)awakeFromNib {
    [super awakeFromNib];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}
-(void)initView{
    _moreBtn =[[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    _moreBtn.backgroundColor = [UIColor whiteColor];
    [_moreBtn setTitle:@"查看更多" forState:UIControlStateNormal];
    _moreBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [_moreBtn setTitleColor:ColorFromRGB(0x666666) forState:UIControlStateNormal];
    [_moreBtn setImage:[UIImage imageNamed:@"icon_see_more"] forState:UIControlStateNormal];
    //button文字在左边图片在右 （button默认是图片右文字左）
    [_moreBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -_moreBtn.imageView.size.width, 0, _moreBtn.imageView.size.width)];
    [_moreBtn setImageEdgeInsets:UIEdgeInsetsMake(0, _moreBtn.titleLabel.bounds.size.width, 0,-_moreBtn.titleLabel.bounds.size.width)];
    [_moreBtn addTarget:self action:@selector(clickMoreBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:_moreBtn];
    _moreBtn.sd_layout.leftSpaceToView(self.contentView, 0)
    .rightSpaceToView(self.contentView, 0).topSpaceToView(self.contentView, 0);
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self setupAutoHeightWithBottomView:_moreBtn bottomMargin:0];
    
}

#pragma 设置按钮的title和image
-(void)setBtnTitle:(int)rows{
    [_moreBtn setTitle:[NSString stringWithFormat:@"查看更多(%d)",rows] forState:UIControlStateNormal];
    [_moreBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -_moreBtn.imageView.size.width, 0, _moreBtn.imageView.size.width)];
    [_moreBtn setImageEdgeInsets:UIEdgeInsetsMake(0, _moreBtn.titleLabel.bounds.size.width, 0,-_moreBtn.titleLabel.bounds.size.width)];
    if(rows == 0){
        _moreBtn.hidden = YES;
    }
   
}


//调用block
-(void)clickMoreBtn{
    if(self.onclickMoerBtn){
        self.onclickMoerBtn();
    }
}

@end
